package com.qst.mapreduce.wordcount.diliuzhang.zuoye.sort;

import com.qst.mapreduce.wordcount.diliuzhang.zuoye.mywc.CustomPartitioner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortAppDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        // 1 获取配置信息以及获取job对象
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2 关联本Driver程序的jar
        job.setJarByClass(SortAppDriver.class);

        // 3 关联Mapper和Reducer的jar
        job.setMapperClass(SortAppMapper.class);
        job.setReducerClass(SortReduce.class);

        // 4 设置Mapper输出的kv类型
        job.setMapOutputKeyClass(SortApp.class);
        job.setMapOutputValueClass(Text.class);

        // 5 设置最终输出kv类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(SortApp.class);

        //设置分区/Reduce任务个数
      /*  job.setNumReduceTasks(2);
        job.setPartitionerClass(CustomPartitioner.class); */
        //设置分区规则（选择用户自定义分区）

        // 6 设置输入和输出路径
        FileInputFormat.setInputPaths(job, new Path("E:\\changyongruanjian\\dashujuJava\\JavaAPPneirong\\shujukucode\\MapReduceDemo\\MapReduceDemo\\output"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\changyongruanjian\\dashujuJava\\JavaAPPneirong\\shujukucode\\MapReduceDemo\\MapReduceDemo\\output5"));

        /*FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));*/

        // 7 提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
